package com.yang.provider.service.impl;

import com.yang.provider.entity.Stock;
import com.yang.provider.mapper.StockMapper;
import com.yang.provider.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：YangRan
 * @date ：Created in 2021/11/24 14:26
 * @description：StockServerImpl
 * @modified By：
 * @version: 1.0
 */
@Service
public class StockServerImpl implements StockService {

    @Autowired
    private StockMapper stockMapper;

    /**
     * 减库存
     * @param id
     * * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean decrease(Integer id) {
        Stock one = stockMapper.selectById(id);
        int stockNum = one.getStockNum() - 1;
        one.setStockNum(stockNum);
        stockMapper.updateById(one);
        return true;
    }

    @Override
    public Stock getOne(Integer id) {
        Stock one = stockMapper.selectById(id);
        return one;
    }
}
